package com.project.controrller;

import com.project.bean.ShoppBean;
import com.project.bean.UserBean;
import com.project.service.IShoppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("shopp")
public class ShoppController {
    @Autowired
    private IShoppService shoppService;
    @RequestMapping("addShopp")
    public String addShopp(Integer productId, HttpServletRequest req){
        //得到登录用户信息
        UserBean user=(UserBean) req.getSession().getAttribute("loginUser");
        shoppService.add(productId,user.getId());
        return "ok";
    }
    @RequestMapping("remove")
    public String remove(Integer shoppId){
        shoppService.del(shoppId);
        return "ok";
    }
    @RequestMapping("update")
    public String update(Integer shoppId,Integer num){
        shoppService.update(shoppId,num);
        return "ok";
    }
    @RequestMapping("findShopp")
    public List<ShoppBean> findShopp(HttpServletRequest req){
        UserBean user=(UserBean) req.getSession().getAttribute("loginUser");
        return shoppService.findByUser(user.getId());
    }
}
